package com.winglinks.message;

import com.alibaba.fastjson2.JSON;
import com.winglinks.domain.ModelType;
import com.winglinks.utils.DateUtils;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ThreadLocalRandom;

/**
 * @author wangzhong
 * @description: TODO
 * @date 2024/2/28 15:44
 */
@Component
public class ImageMessageProduct implements MessageProduct  {


    private static final String model = ModelType.IMAGE.getModel();
    /**
     * 生产topic
     *
     * @param gatewayIdentification
     * @return
     */
    @Override
    public String generateTopic(String gatewayIdentification) {
        String topic = "/v1/devices/"+gatewayIdentification+"/datas";
        return topic;
    }

    /**
     * 获取消息model
     *
     * @return
     */
    @Override
    public String getModel() {
        return model;
    }

    /**
     * 生产消息
     *
     * @param deviceIdentification
     * @return
     */
    @Override
    public String generateMsg(String deviceIdentification) {
        Map<String,Object> result = new HashMap<>();
        Map<String,Object> data = new HashMap<>();
        Map<String,Object> service = new HashMap<>();
        List<Map<String,Object>> services = new ArrayList<>();
        Map<String,Object> device = new HashMap<>();
        List<Map<String,Object>> devices = new ArrayList<>();


        //获取当前时间
        String date = DateUtils.dateTimeNow(DateUtils.YYYYMMDDTHHMMSSZ);
        ThreadLocalRandom rand = ThreadLocalRandom.current();
        // 生产数据
        data.put("channel_no",0);
        data.put("presetting_no",255);
        data.put("file_path","https://pro-test.thinglinks.mqttsnet.com/assets/deviceTotal.4bd1fa84.png");

        service.put("data",data);
        service.put("eventTime",date);
        service.put("serviceId","analog");

        services.add(service);
        device.put("services",services);
        device.put("deviceId",deviceIdentification);
        devices.add(device);
        result.put("devices",devices);


        return JSON.toJSONString(result);
    }

    /**
     * 产品匹配
     *
     * @param model
     * @return
     */
    @Override
    public boolean isSupport(String model) {
        return this.getModel().equals(model);
    }
}
